import 'package:flutter/material.dart';
import 'package:flutterdemo/common/calc.dart';
import 'package:flutterdemo/components/avatar.dart';

class Chat extends StatefulWidget {
  Chat({Key? key}) : super(key: key);

  @override
  _ChatState createState() => _ChatState();
}

class _ChatState extends State<Chat> {
// 每个item
  Widget _chatItemWidget(
      String avatar, String nickname, String msg, String time) {
    return Ink(
      color: Colors.white,
      child: InkWell(
      onTap: () {
        Navigator.pushNamed(context, "chatInfo");
      },
      child: Padding(
        padding: EdgeInsets.fromLTRB(
            Calc.width(30), Calc.width(20), Calc.width(30), Calc.width(20)),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Avatar(avatar),
            Expanded(
                flex: 1,
                child: Padding(
                  padding: EdgeInsets.only(
                      left: Calc.width(20), right: Calc.width(20)),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                          width: double.infinity,
                          child: Text(nickname,
                              style: TextStyle(fontSize: Calc.width(30)))),
                      Container(
                        width: double.infinity,
                        child: Text(msg,
                            style: TextStyle(
                                fontSize: Calc.width(24), color: Colors.grey)),
                      ),
                    ],
                  ),
                )),
            Text(
              time,
              style: TextStyle(color: Colors.grey, fontSize: Calc.width(24)),
            )
          ],
        ),
      ),
    ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromRGBO(233, 233, 233, 1),
        body: ListView(
          physics: BouncingScrollPhysics(),
      children: [
        _chatItemWidget(
            "https://shangguling-live.oss-cn-shenzhen.aliyuncs.com/uploads/20210917/7cfc8b3c0a4bcef10a5dc449175319ba.png",
            "黄颖哈哈哈",
            "又有切克闹",
            "5天前"),
        _chatItemWidget(
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ffs-uc-nearme-com-cn.oss-cn-hangzhou.aliyuncs.com%2F771%2F837%2F743%2F347738177.jpg%3F20180225111709&refer=http%3A%2F%2Ffs-uc-nearme-com-cn.oss-cn-hangzhou.aliyuncs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642403591&t=8cf06531d469ff8f9d07f4bb78a6cb78",
            "马化腾",
            "借点钱大哥！",
            "5天前"),
        _chatItemWidget(
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13445984193%2F641.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642403571&t=e6826dd502bf18ceb833b278431487f7",
            "马云",
            "呦呦呦，小老弟",
            "5天前"),
        _chatItemWidget(
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F052420110515%2F200524110515-11-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642403281&t=daa07b534d2458765f944bae1c0c041c",
            "做个人吧",
            "哦哦哦哦哦，真好",
            "5天前"),
        _chatItemWidget(
            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.hinews.cn%2Fpic%2F0%2F11%2F30%2F88%2F11308896_313124.jpg&refer=http%3A%2F%2Fwww.hinews.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642403626&t=a7566f84dd571abe2b8e48a011ece052',
            "我是大美女",
            "约吗，兄弟！",
            "5天前"),
      ],
    ));
  }
}
